using System;
using System.Collections.Concurrent;

namespace DapperExtensionsNew
{
    public static class ConnectionStringConfig
    {
        private static readonly ConcurrentDictionary<string, string> Config = new ConcurrentDictionary<string, string>();

        internal static void AddConnectionString(string connectionName, string connectionString)
        {
            Config.TryAdd(connectionName, connectionString);
        }

        public static string GetConnectionString(string connectionName)
        {
            if (!Config.TryGetValue(connectionName, out string value) || string.IsNullOrEmpty(value))
            {
                throw new Exception("未设置" + connectionName + "连接字符串");
            }
            return value;
        }
    }
}
